/*
 * @Description:
 * @Author: ZY
 * @Date: 2020-12-07 10:30:20
 * @LastEditors: ZY
 * @LastEditTime: 2021-01-27 20:10:59
 */
import { createRouter, createWebHashHistory, createWebHistory, RouteRecordRaw } from 'vue-router';
import Dashboard from '@/views/dashboard/index.vue';
import Module from '@/views/module/index.vue';
import Make from '@/views/make/index.vue';
import My from '@/views/my/index.vue';
import Index from '@/views/index/index.vue';

import { store } from '../store/index.js';

export const constantRoutes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: Index,
    meta: {},
  },
  {
    path: '/dashboard',
    component: Dashboard,
    meta: {
      requiresAuth: false,
    },
  },
  {
    path: '/dashboard/:id',
    component: Dashboard,
    meta: {
      requiresAuth: false,
    },
  },
  {
    path: '/module',
    component: Module,
  },
  {
    path: '/make',
    component: Make,
  },
  {
    path: '/make/:id',
    component: Make,
  },
  {
    path: '/user',
    component: My,
    meta: {
      requiresAuth: false,
    },
  },
];

const router = createRouter({
  history: import.meta.env.DEV ? createWebHashHistory() : createWebHistory(),
  routes: constantRoutes,
});

// router.afterEach((to, from) => {
//   console.log(store.state.user)
//   if (to.meta.requiresAuth && !store.state.user.userInfo && store.state.common.appReady) {
//     store.commit('common/setParams', { loginDisplay: true })
//   }
// })

export default router;
